```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot异步处理实战指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #4a6cf7 100%);
        }
        .code-block {
            background: #2d3748;
            border-left: 4px solid #4a6cf7;
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .icon-circle {
            width: 60px;
            height: 60px;
        }
        .step-number {
            width: 32px;
            height: 32px;
            line-height: 32px;
        }
        .fade-in {
            animation: fadeIn 0.5s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-5xl text-center fade-in">
            <h1 class="text-4xl md:text-6xl font-bold mb-6 font-serif">Spring Boot 异步处理</h1>
            <p class="text-xl md:text-2xl mb-8 max-w-3xl mx-auto">提升应用性能的现代并发解决方案</p>
            <div class="flex justify-center space-x-4">
                <a href="#intro" class="px-6 py-3 bg-white text-blue-600 font-medium rounded-lg hover:bg-gray-100 transition duration-300">
                    <i class="fas fa-book-open mr-2"></i>开始学习
                </a>
                <a href="#demo" class="px-6 py-3 bg-transparent border-2 border-white text-white font-medium rounded-lg hover:bg-white hover:text-blue-600 transition duration-300">
                    <i class="fas fa-code mr-2"></i>查看示例
                </a>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section id="intro" class="py-16 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center mb-16">
                <h2 class="text-3xl md:text-4xl font-bold mb-4 font-serif">为什么需要异步处理？</h2>
                <p class="text-gray-600 max-w-2xl mx-auto text-lg">在现代Web应用中，异步处理是提高性能和用户体验的关键技术。通过将耗时操作放在后台线程执行，可以让主线程快速响应用户请求。</p>
            </div>
            
            <div class="grid md:grid-cols-3 gap-8 mb-16">
                <div class="feature-card bg-white p-8 rounded-xl shadow-md transition duration-300">
                    <div class="icon-circle bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mb-6 mx-auto">
                        <i class="fas fa-bolt text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">提升响应速度</h3>
                    <p class="text-gray-600">异步处理允许主线程立即返回，而耗时操作在后台执行，大大提高系统响应速度。</p>
                </div>
                <div class="feature-card bg-white p-8 rounded-xl shadow-md transition duration-300">
                    <div class="icon-circle bg-purple-100 text-purple-600 rounded-full flex items-center justify-center mb-6 mx-auto">
                        <i class="fas fa-chart-line text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">提高吞吐量</h3>
                    <p class="text-gray-600">通过利用多线程并行处理请求，系统可以同时服务更多用户，提高整体吞吐量。</p>
                </div>
                <div class="feature-card bg-white p-8 rounded-xl shadow-md transition duration-300">
                    <div class="icon-circle bg-green-100 text-green-600 rounded-full flex items-center justify-center mb-6 mx-auto">
                        <i class="fas fa-cogs text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">优化资源利用</h3>
                    <p class="text-gray-600">合理分配计算资源，避免线程阻塞，最大化利用服务器CPU和I/O资源。</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section id="demo" class="py-8 px-4 bg-gray-100">
        <div class="container mx-auto max-w-5xl">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 fade-in">
                <div class="p-6 md:p-8">
                    <h2 class="text-2xl md:text-3xl font-bold mb-6 font-serif">1. 配置异步支持</h2>
                    <p class="text-gray-700 mb-6">在Spring Boot项目中启用异步支持非常简单，只需在配置类上添加<code class="bg-gray-100 px-2 py-1 rounded">@EnableAsync</code>注解。</p>
                    
                    <div class="code-block rounded-lg overflow-hidden mb-6">
                        <pre class="text-gray-200 p-4 overflow-x-auto"><code>import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

@Configuration
@EnableAsync
public class AsyncConfig {
    // 可以在这里配置异步执行器（Executor）等其他异步相关的配置
}</code></pre>
                    </div>
                    
                    <div class="bg-blue-50 border-l-4 border-blue-500 p-4">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-info-circle text-blue-500 mt-1"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-blue-700">
                                    <code>@EnableAsync</code>注解启用了Spring的异步方法执行功能，这是使用<code>@Async</code>注解的前提条件。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 fade-in">
                <div class="p-6 md:p-8">
                    <h2 class="text-2xl md:text-3xl font-bold mb-6 font-serif">2. 使用@Async注解</h2>
                    <p class="text-gray-700 mb-6">在需要异步执行的方法上添加<code class="bg-gray-100 px-2 py-1 rounded">@Async</code>注解，此方法就会在单独的线程中运行。</p>
                    
                    <div class="code-block rounded-lg overflow-hidden mb-6">
                        <pre class="text-gray-200 p-4 overflow-x-auto"><code>import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class AsyncService {

    @Async
    public void performAsyncTask() {
        try {
            System.out.println("开始异步任务");
            Thread.sleep(5000); // 模拟耗时操作
            System.out.println("异步任务完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}</code></pre>
                    </div>
                    
                    <ul class="space-y-3 mb-6">
                        <li class="flex items-start">
                            <div class="flex-shrink-0 step-number bg-blue-500 text-white rounded-full text-center text-sm font-bold mr-3">1</div>
                            <p class="text-gray-700">方法必须定义在Spring管理的Bean中（使用<code class="bg-gray-100 px-1 py-0.5 rounded">@Component</code>、<code class="bg-gray-100 px-1 py-0.5 rounded">@Service</code>等注解）</p>
                        </li>
                        <li class="flex items-start">
                            <div class="flex-shrink-0 step-number bg-blue-500 text-white rounded-full text-center text-sm font-bold mr-3">2</div>
                            <p class="text-gray-700">调用异步方法的类必须通过Spring注入，不能直接new实例</p>
                        </li>
                        <li class="flex items-start">
                            <div class="flex-shrink-0 step-number bg-blue-500 text-white rounded-full text-center text-sm font-bold mr-3">3</div>
                            <p class="text-gray-700">同一个类内部调用异步方法不会生效，因为Spring AOP代理的限制</p>
                        </li>
                    </ul>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 fade-in">
                <div class="p-6 md:p-8">
                    <h2 class="text-2xl md:text-3xl font-bold mb-6 font-serif">3. 自定义线程池</h2>
                    <p class="text-gray-700 mb-6">默认线程池可能不适合生产环境，Spring允许我们自定义线程池配置。</p>
                    
                    <div class="code-block rounded-lg overflow-hidden mb-6">
                        <pre class="text-gray-200 p-4 overflow-x-auto"><code>import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class AsyncConfig {

    @Bean(name = "taskExecutor")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);  // 核心线程数
        executor.setMaxPoolSize(10);  // 最大线程数
        executor.setQueueCapacity(25); // 队列容量
        executor.setThreadNamePrefix("Async-"); // 线程名前缀
        executor.initialize();
        return executor;
    }
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-6">
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <h4 class="font-bold text-gray-800 mb-2">配置参数说明</h4>
                            <ul class="space-y-2 text-sm text-gray-700">
                                <li><span class="font-medium">corePoolSize:</span> 核心线程数，即使空闲也会保留</li>
                                <li><span class="font-medium">maxPoolSize:</span> 最大线程数，当队列满时创建</li>
                                <li><span class="font-medium">queueCapacity:</span> 任务队列容量</li>
                                <li><span class="font-medium">keepAliveSeconds:</span> 非核心线程空闲存活时间</li>
                            </ul>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <h4 class="font-bold text-gray-800 mb-2">使用自定义线程池</h4>
                            <div class="code-block rounded-lg overflow-hidden">
                                <pre class="text-gray-700 p-3 text-sm overflow-x-auto bg-gray-100"><code>@Async("taskExecutor")
public void performAsyncTask() {
    // 使用自定义线程池执行的异步任务
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 fade-in">
                <div class="p-6 md:p-8">
                    <h2 class="text-2xl md:text-3xl font-bold mb-6 font-serif">4. 返回值处理</h2>
                    <p class="text-gray-700 mb-6">异步方法可以返回<code class="bg-gray-100 px-2 py-1 rounded">Future</code>、<code class="bg-gray-100 px-2 py-1 rounded">CompletableFuture</code>或<code class="bg-gray-100 px-2 py-1 rounded">ListenableFuture</code>，以便在任务完成后获取结果。</p>
                    
                    <div class="code-block rounded-lg overflow-hidden mb-6">
                        <pre class="text-gray-200 p-4 overflow-x-auto"><code>import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

@Service
public class AsyncService {

    @Async
    public Future&lt;String&gt; performAsyncTaskWithReturn() {
        try {
            Thread.sleep(5000); // 模拟耗时操作
            return new AsyncResult&lt;&gt;("任务完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
            return new AsyncResult&lt;&gt;("任务失败");
        }
    }

    @Async
    public CompletableFuture&lt;String&gt; performAsyncTaskWithCompletableFuture() {
        try {
            Thread.sleep(5000); // 模拟耗时操作
            return CompletableFuture.completedFuture("任务完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
            return CompletableFuture.completedFuture("任务失败");
        }
    }
}</code></pre>
                    </div>
                    
                    <div class="bg-yellow-50 border-l-4 border-yellow-500 p-4 mb-6">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-exclamation-triangle text-yellow-500 mt-1"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-yellow-700">
                                    调用方可以通过<code class="bg-yellow-100 px-1 py-0.5 rounded">Future.get()</code>方法获取异步方法的结果，但要注意这会阻塞当前线程直到结果可用。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 fade-in">
                <div class="p-6 md:p-8">
                    <h2 class="text-2xl md:text-3xl font-bold mb-6 font-serif">5. 异常处理</h2>
                    <p class="text-gray-700 mb-6">异步方法中的异常默认不会被直接捕获，需要特殊处理。</p>
                    
                    <div class="code-block rounded-lg overflow-hidden mb-6">
                        <pre class="text-gray-200 p-4 overflow-x-auto"><code>import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.annotation.AsyncConfigurer;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(25);
        executor.setThreadNamePrefix("Async-");
        executor.initialize();
        return executor;
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return (ex, method, params) -> System.out.println("异步方法 '" + method.getName() + "' 抛出异常: " + ex.getMessage());
    }
}</code></pre>
                    </div>
                    
                    <div class="bg-blue-50 border-l-4 border-blue-500 p-4">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-lightbulb text-blue-500 mt-1"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-blue-700">
                                    对于返回<code class="bg-blue-100 px-1 py-0.5 rounded">Future</code>的异步方法，异常会封装在<code class="bg-blue-100 px-1 py-0.5 rounded">Future</code>对象中，调用<code class="bg-blue-100 px-1 py-0.5 rounded">get()</code>方法时会抛出<code class="bg-blue-100 px-1 py-0.5 rounded">ExecutionException</code>。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Concept Visualization -->
    <section class="py-16 px-4 bg-white">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl md:text-4xl font-bold mb-12 text-center font-serif">异步处理概念图解</h2>
            
            <div class="bg-gray-50 p-6 rounded-xl shadow-sm">
                <div class="mermaid">
                    graph TD
                        A[客户端请求] --> B[主线程]
                        B --> C{是否有耗时操作?}
                        C -->|否| D[同步处理]
                        C -->|是| E[使用@Async]
                        E --> F[异步线程池]
                        F --> G[执行耗时操作]
                        G --> H[返回Future或void]
                        D --> I[返回响应]
                        H --> I
                </div>
            </div>
            
            <div class="grid md:grid-cols-3 gap-8 mt-12">
                <div class="p-6 border border-gray-200 rounded-lg">
                    <h3 class="text-xl font-bold mb-3 flex items-center">
                        <i class="fas fa-sync-alt text-blue-500 mr-2"></i> 同步处理
                    </h3>
                    <p class="text-gray-600">请求线程必须等待所有操作完成才能返回响应，导致响应时间延长。</p>
                </div>
                <div class="p-6 border border-gray-200 rounded-lg">
                    <h3 class="text-xl font-bold mb-3 flex items-center">
                        <i class="fas fa-random text-purple-500 mr-2"></i> 异步处理
                    </h3>
                    <p class="text-gray-600">主线程立即返回，耗时操作由后台线程处理，大幅提升响应速度。</p>
                </div>
                <div class="p-6 border border-gray-200 rounded-lg">
                    <h3 class="text-xl font-bold mb-3 flex items-center">
                        <i class="fas fa-tasks text-green-500 mr-2"></i> 线程池管理
                    </h3>
                    <p class="text-gray-600">通过线程池管理异步线程，避免频繁创建销毁线程的开销，提高资源利用率。</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Best Practices -->
    <section class="py-16 px-4 bg-gray-100">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl md:text-4xl font-bold mb-12 text-center font-serif">最佳实践与注意事项</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <h3 class="text-xl font-bold mb-4 flex items-center text-blue-600">
                        <i class="fas fa-check-circle mr-2"></i> 适用场景
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>发送电子邮件或短信通知</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>文件上传/下载处理</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>大数据处理或报表生成</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>调用外部API或微服务</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <h3 class="text-xl font-bold mb-4 flex items-center text-red-600">
                        <i class="fas fa-exclamation-triangle mr-2"></i> 注意事项
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>避免在异步方法中处理事务，可能导致事务失效</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>同类内调用异步方法不会生效</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>合理设置线程池参数，避免OOM</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>考虑异步任务的幂等性和重试机制</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p>专业的Java技术分享平台</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="hover:text-white transition duration-300" target="_blank">
                        <i class="fas fa-globe mr-2"></i>www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <!-- Mermaid.js -->
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // Add fade-in animation for scroll
        document.addEventListener('DOMContentLoaded', function() {
            const fadeElements = document.querySelectorAll('.fade-in');
            
            const observer = new IntersectionObserver((entries) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        entry.target.classList.add('opacity-100');
                    }
                });
            }, {
                threshold: 0.1
            });
            
            fadeElements.forEach(el => {
                el.classList.add('opacity-0');
                observer.observe(el);
            });
        });
    </script>
</body>
</html>
```